package firbi.base;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.google.android.maps.GeoPoint;

import firbi.base.com.Bus;
import firbi.base.com.BusRoute;
import firbi.base.com.BusStop;
import firbi.base.com.FirbiCom;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class TestFirbiCom extends Activity {
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test_firbicom);
        
        ((Button)findViewById(R.id.test_firbicom_button)).setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
            	Bus[] result = FirbiCom.getStopSchedule(BusStop.updateOrCreate("0001_10020","10020", new GeoPoint(47668579, -122288293), "NE 55th St & 37th Ave NE", null));
            	for(int i=0;i<result.length;i++){
            		((TextView)findViewById(R.id.test_firbicom_text)).append(result[i].toString());
            	}
            }
        });
        
        ((Button)findViewById(R.id.test_firbicom_button2)).setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
            	BusRoute[] result = BusRoute.find("71", new GeoPoint (47619800, -122347000));//FirbiCom.getStops("14035", new GeoPoint (47619800, -122347000));
            	//((TextView)findViewById(R.id.test_firbicom_text)).append(result.toString());
            	for(int i=0;i<result.length;i++){
            		((TextView)findViewById(R.id.test_firbicom_text)).append(result[i].toString());
            	}
            }
        });
        
        ((Button)findViewById(R.id.test_firbicom_button3)).setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
            	Map<String[], BusStop[]> result = BusRoute.find("0001_30").getDirectionKeyedStopsServedByRoute();
            	TextView printo = ((TextView)findViewById(R.id.test_firbicom_text));
            	if(result==null){
            		printo.append("got null from find");
            	}
            	Set<String[]> keys = result.keySet();
            	if(result.keySet()==null){
            		printo.append("got null keyset");
            	}
            	else if(result.keySet().size()<1){
            		printo.append("got no values in keyset");
            	}
            	Iterator<String[]> i = keys.iterator();
            	while(i.hasNext()){
            		String[] key = i.next();
            		FirbiCom.print("{");
            		for(int j = 0; j < key.length; j++){
            			printo.append(key[j]+",");
            		}
            		printo.append("}=>");
            		BusStop[] buses = result.get(key);
            		printo.append("{");
            		for(int j = 0; j < buses.length; j++){
            			printo.append(buses[j].getId()+",");
            		}
            		printo.append("}   ");
            	}
            }
        });
        
        
    }
	
}
